<include file="Public/mobile_head"/>	
<!--<link href="{:ADDON_PUBLIC_PATH}/vote.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">-->
<link href="{:ADDON_PUBLIC_PATH}/css/merList.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container body ">
	<div class="vote_wrap  ">
		<div class="img_wrap">
			<img width="100%" src="{$info.picurl|get_cover_url}"></div>
		<!--<h2 style="position:static">-->
			<!--<div style="word-wrap:break-word;">{$info.title}</div>-->
		<!--</h2>-->
		<P class="total_vote" style="display: none;">
			总共有
			<span id="totalCount">{$info.vote_count}</span>
			人投票
		</P>
		<form id="form1" name="form1" method="post" action="{:U( 'join' )}" onSubmit="return checkForm();">
			<div class="merListCen clearfix choice_list <if condition="$info['is_img'] && !empty($opt['image'])">img_choice</if> ">
				<ul class="merList">
					<volist name='opts' id='opt' key="k">
						<!-- 带图片投票 -->
						<if condition="$info['is_img'] && !empty($opt['image'])">
							<li class="merItem <if condition="$canJoin eq false">disable</if> " data-count="{$opt.opt_count}">
								<img <php> if(in_array($opt[id], $joinData)) echo 'style="border-color:#c07b36" '; </php> src="{$opt.image|get_cover_url}" class="merPic" />
								<div class="merInfoBar">
									<div class="merTitleBar">
										<h2 class="merTitle">{$opt.name|msubstr=0,15}</h2>
										<a href="{$opt.url}" class="merInfoMore">了解我></a>
									</div>
									<div class="merDePiaoBar">
										<span class="piaoNum ">总票数：<font class="count_num">{$opt.opt_count}票</font></span>

										<notempty name="vote_options_arr">
											<php>if(in_array($opt[id], $vote_options_arr)){ </php>
												<a href="javascript:;" class="taoPiaoBtn taoPiaoBtnYt">已投</a>
											<php>	} else{ </php>
												<a href="javascript:;" class="taoPiaoBtn">投一票</a>
											<php> } </php>
										<else />
											<a href="javascript:;" class="taoPiaoBtn">投一票</a>
										</notempty>
									</div>
								</div>
						<else/>
							<li class="text_li <if condition="$canJoin eq false">disable</if>" data-count="{$opt.opt_count}">
								<div class="bar" <php>if(in_array($opt[id], $joinData)) echo 'style="font-weight:bold" ';</php> >
									<p>
										<span class="name">{$opt.name|msubstr=0,15}</span>
									</p>
									<p class="count">
										<span class="count_num">{$opt.opt_count}</span>票
									</p>
									<div class="progress"></div>
								</div>
						</if>
							<p class="list" style="display:none">
								<input type="radio" class="{$style_cls}" id="check_{$opt.id}" name="optArr[]" value="{$opt.id}"
								<php> //if(in_array($opt[id], $joinData)) echo 'checked="checked" '; if(!$canJoin) echo ' disabled'; </php> >
								<label for="check_{$opt.id}"></label>
							</p>
						</li>
					</volist>
				</ul>
			</div>

			<div class="warning" id="errorInfo"></div>
			<input type="hidden" value="{:I('token')}" name="token" />
			<input type="hidden" value="{:I('wecha_id')}" name="wecha_id" />
			<input type="hidden" value="{$info.id}" name="vote_id" />

		</form>
		</div>
<!--<p class="copyright">{$system_copy_right}</p>-->
</div>

<!-- 弹窗 -->
<div class="tcBg">
	<div class="tc">
		<div class="tcHeader">
			<h1 class="tcHeaderTitle">通知</h1>
			<a href="javascript:;" class="closeBtn"></a>
		</div>
		<div class="tcCenBar">
			<div class="tcTishiInfoBar">
				<span>投票成功！</span>
				<p>关注我们即可参与刮奖活动！</p>
			</div>
			<div class="erweimaBar">
				<img src="{:ADDON_PUBLIC_PATH}/images/erweima.jpg" class="erweimaPic" />
			</div>
			<div class="saomaBar">
				<div class="saomaCen">
					<i class="saomaTishiPic"></i>
					<div class="saomaWzTishi">
						<span>长按二维码！</span>
						<p>即可关注N37公众微信号</p>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<include file="Public/mobile_foot"/>
<script type="text/javascript">
	$.WeiPHP.initWxShare({
		title:"{$info.title}",
		imgUrl:"{$info.picurl|get_cover_url}",
		desc:"{$info.description}",
		link:window.location.href
	})
</script>
</body>
</html>
<script>
function initProgressBar(){
	var totalCount = parseInt($('#totalCount').text());
	$('.text_li').each(function(index, element) {
        var count = parseInt($(this).find('.count_num').text());
		var percent = (count/totalCount)*100+"%";
		$(this).find('.progress').width(percent).css('background-color',WeiPHP_RAND_COLOR[index]);
    });
}
$(document).ready(function(){
	initProgressBar();
	$(".choice_list .taoPiaoBtn").click(function () {
		var overtime="{$overtime}";
		 if($(this).hasClass('disabled'))
		 {
			 if(overtime=='1'){
				 $.Dialog.confirm("提示","该投票已过期");
			}else{
			 	$.Dialog.confirm("提示","你已经投过票了2");
			}
		   return;
		 }
		 else
		 {
				var this_obj = $(this);
				$(".choice_list li").addClass('disable');
				$(this).parents(".merItem").find(".list").find("input").prop("checked", true);
				var url = $('#form1').attr('action');
				var param = $('#form1').serializeArray();
				 if( !this_obj.hasClass("taoPiaoBtnYt") && jQuery(".taoPiaoBtnYt").length < 3 )
				 {
					 //alert(num);
					 this_obj.addClass("taoPiaoBtnYt").text("已投");
//					 num -- ;
					 //在三次内可以投递
					 $.post(url,param,function(data)
					 {
						 if(data.status == 0)
						 {
							 //以及其他未知错误信息
							 $.Dialog.confirm('提示',data.info);
						 }
						 else
						 {
							 this_obj.parents(".merDePiaoBar").find('.count_num').text((parseInt(this_obj.parents(".merDePiaoBar").find('.count_num').text())+1));
							 //投票成功
							 $('.tcBg').css('display','block');
							 $(this).find('img').css('border-color','#c07b36');
							 var totalCount = parseInt($('#totalCount').text());
							 $('#totalCount').text(totalCount+1);
							 //重新算进度条
							 initProgressBar();
						 }
					 })
				 }
		         else
				 {
//					 $.Dialog.confirm("提示","今天已经投过3次了!");
				 }

	      }
	 });
	 /*
	if (typeof WeixinJSBridge == "undefined"){
		if( document.addEventListener ){
			document.addEventListener('WeixinJSBridgeReady', init_close, false);
		}else if (document.attachEvent){
			document.attachEvent('WeixinJSBridgeReady', init_close); 
			document.attachEvent('onWeixinJSBridgeReady', init_close);
		}
	}else{
		init_close();
	}	
	*/
//	关闭弹窗
	$(".closeBtn").bind("click",function(){
		$('.tcBg').css('display','none');
	});



//	$(".taoPiaoBtn").bind("click",function()
//	{
//		$.post(url,param,function(data)
//		{
//			if(data.status == 0)
//			{
//				//以及其他未知错误信息
//				$.Dialog.confirm('提示',data.info);
//			}
//			else
//			{
////								alert(data);
//				this_obj.parents(".merDePiaoBar").find('.count_num').text((parseInt(this_obj.parents(".merDePiaoBar").find('.count_num').text())+1));
//				//投票成功
//				$('.tcBg').css('display','block');
//				$(this).find('img').css('border-color','#c07b36');
//
//
//				var totalCount = parseInt($('#totalCount').text());
//				$('#totalCount').text(totalCount+1);
//				//重新算进度条
//				initProgressBar();
//			}
//		});
//	});

});
</script>